import { serviceGetSystemInfo } from '../../request/system'
import { Dispatch } from 'redux'

export function setSystemInfo(data: any = {}) {
  return { type: 'INFO', data }
}

// 获取系统信息
export function getSystemInfo() {
  return function (dispatch: Dispatch, getState: () => any) {
    // 两次解构赋值
    const {
      system: { info },
    } = getState()
    if (info.nodeVersion) {
      return dispatch(setSystemInfo())
    }
    return serviceGetSystemInfo().then(res => {
      if (res.data.success) {
        const data = res.data.data
        return dispatch(setSystemInfo(data))
      }
      return dispatch(setSystemInfo())
    })
  }
}
